package org.mspring.mlog.web.admin;

import org.mspring.mlog.cache.NodeCacheService;
import org.mspring.mlog.web.BaseAdminController;
import org.mspring.mlog.entity.NodeEntity;
import org.mspring.mlog.entity.UserEntity;
import org.mspring.nbee.web.support.WebContext;
import org.mspring.nbee.web.view.json.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author Gao Youbo
 * @since 2014年10月24日
 */
@Controller
@RequestMapping("/admin")
public class MenuController extends BaseAdminController {
    private NodeCacheService nodeCacheService;

    @RequestMapping("/tabs")
    @ResponseBody
    public JsonResult tabs(WebContext context) {
        String id = context.getRequiredParam("id");
        UserEntity user = getCurrentUser();
        List<NodeEntity> tabs = nodeCacheService.getTabNode(id, user.getId());
        return JsonResult.getJsonResult(tabs);
    }

    @Autowired
    public void setNodeCacheService(NodeCacheService nodeCacheService) {
        this.nodeCacheService = nodeCacheService;
    }
}
